<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<h1>某某博客</h1>
<img src="./8.png" alt="">

<input type="file" name="hehe" class="upfile">
<button class="btn">上传图片</button>
<img class="show" src="" alt="">
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>

$('.btn').click(function (){
    let file = $('.upfile')[0].files[0] //要上传的文件对象
    // console.log( file )

    // 创建一个空的formData对象
    let formData = new FormData()
    // 将文件对象添加到formData对象中
    formData.append('hehe',file)

    $.ajax({
        url: 'http://localhost:3003/file/upload',
        type: 'post',
        data: formData,
        processData: false,// *
        contentType: false,// *
        success: function (data){
            console.log( data )
            $('.show').attr('src',data.imgurl)
        }
    })
})

</script>
</body>
</html>